/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

/**
 *
 * @author James
 */
@Entity
public class Partner implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long    id;
    private String  name;
    private String  businessAddress1;
    private String  businessAddress2;
    private String  businessPostalCode;
    private String  billingAddress1;
    private String  billingAddress2;
    private String  billingPostalCode;
    private String  countryCode;
    private String  phone;
    private String  country;
    private String  province;
    private String  city;
    private String  timezone;
    private String  businessEmail;
    private String  notificationURL;
    private long    registeredDate;
    private int     sector;
    private int     ratedPoint;
    private int     numOfRater;
    private int     reservationNoShowFee; // dollar * 100 + cents ($2.5 = 250)
    private int     reservationCancelFee; // dollar * 100 + cents ($2.5 = 250)
    private int     reservableMinimumLength; // postive: number of minutes, 0: reservation not allowed
    private int     reservableMaximumLength; // postive: number of minutes, 0: reservation not allowed
    private int     reservationMinimumLeadTime; // postive: number of minutes
    private int     reservationMaximumLeadTime; // postive: number of minutes
    private boolean branch;
    private boolean active;
    private boolean deleted;
    @OneToMany(cascade={CascadeType.PERSIST})
    private List<Files>  listOfInvoices; // if the PDF invoice generating process is slow, we may need this field to store the PDF after it is generated each month so that it would only be generated once. Subsequent request for invoice will be from here.
    @OneToMany(cascade={CascadeType.ALL}, mappedBy="thePartner")
    private List<Review> listOfReviews; //20 latest reviews
    @OneToMany(cascade={CascadeType.ALL}, mappedBy="thePartner")
    private List<ItemCategory> sellingItemCategories; // This is default menus for all outlets
    @OneToOne
    private PartnerAccount manager;
    @OneToMany(cascade={CascadeType.ALL}, mappedBy="thePartner")
    private List<PartnerAccount> listOfEmployees;
    @OneToMany(cascade={CascadeType.PERSIST})
    private List<Partner> listOfBranches;
    @OneToMany(cascade={CascadeType.ALL}, mappedBy="thePartner")
    private List<Outlet> listOfOutlets;
    @OneToMany(cascade={CascadeType.ALL})
    private List<TermsAndConditions> listOfTC;
    
    public Partner() {
        this.registeredDate        = System.currentTimeMillis();
        this.timezone              = null;
        this.ratedPoint            = 0;
        this.numOfRater            = 0;
        this.reservationNoShowFee  = 0;
        this.reservationCancelFee  = 0;
        this.reservableMinimumLength    = 0;
        this.reservableMaximumLength    = 0;
        this.reservationMinimumLeadTime = 0;
        this.reservationMaximumLeadTime = 0;
        this.active                = false;
        this.deleted               = false;
        this.listOfInvoices        = new ArrayList<Files>();
        this.listOfReviews         = new ArrayList<Review>();
        this.sellingItemCategories = new ArrayList<ItemCategory>();
        this.listOfEmployees       = new ArrayList<PartnerAccount>();
        this.listOfBranches        = new ArrayList<Partner>();
        this.listOfOutlets         = new ArrayList<Outlet>();
        this.listOfTC              = new ArrayList<TermsAndConditions>();
    }
    
    public void createPartner(String name, String businessAddress1, String businessAddress2, String businessPostalCode, String billingAddress1, String billingAddress2, String billingPostalCode, String countryCode, String phone, String country, String province, String city, String businessEmail, int sector, boolean branch, PartnerAccount manager) {
        this.name               = name;
        this.businessAddress1   = businessAddress1;
        this.businessAddress2   = businessAddress2;
        this.businessPostalCode = businessPostalCode;
        this.billingAddress1    = billingAddress1;
        this.billingAddress2    = billingAddress2;
        this.billingPostalCode  = billingPostalCode;
        this.countryCode        = countryCode;
        this.phone              = phone;
        this.country            = country;
        this.province           = province;
        this.city               = city;
        this.businessEmail      = businessEmail;
        this.sector             = sector;
        this.branch             = branch;
        this.manager            = manager;
        this.listOfEmployees.add(manager);
        //Always create an online store for new partners
        Outlet onlineOutlet = new Outlet();
        onlineOutlet.createOutlet("Online Store", this.businessAddress1, this.businessAddress2, this.businessPostalCode, this.countryCode, this.phone, this.country, this.province, this.city, this.businessEmail, null, this);
        this.listOfOutlets.add(onlineOutlet);
    }
    
    public void addOutlet(Outlet theOutlet) {
        this.listOfOutlets.add(theOutlet);
    }
    
    public void addItemCategory(ItemCategory theItemCategory) {
        this.sellingItemCategories.add(theItemCategory);
    }
    
    //Getters and Setters
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getTimezone() {
        return timezone;
    }

    public void setTimezone(String timezone) {
        this.timezone = timezone;
    }

    public boolean isActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

    public boolean isDeleted() {
        return deleted;
    }

    public void setDeleted(boolean deleted) {
        this.deleted = deleted;
    }

    public List<Review> getListOfReviews() {
        return listOfReviews;
    }

    public void setListOfReviews(List<Review> listOfReviews) {
        this.listOfReviews = listOfReviews;
    }

    public PartnerAccount getManager() {
        return manager;
    }

    public void setManager(PartnerAccount manager) {
        this.manager = manager;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getNotificationURL() {
        return notificationURL;
    }

    public void setNotificationURL(String notificationURL) {
        this.notificationURL = notificationURL;
    }

    public int getNumOfRater() {
        return numOfRater;
    }

    public void setNumOfRater(int numOfRater) {
        this.numOfRater = numOfRater;
    }

    public int getRatedPoint() {
        return ratedPoint;
    }

    public void setRatedPoint(int ratedPoint) {
        this.ratedPoint = ratedPoint;
    }

    public List<ItemCategory> getItemCategories() {
        return sellingItemCategories;
    }

    public void setItemCategories(List<ItemCategory> sellingItemCategories) {
        this.sellingItemCategories = sellingItemCategories;
    }

    public long getRegisteredDate() {
        return registeredDate;
    }

    public void setRegisteredDate(long registeredDate) {
        this.registeredDate = registeredDate;
    }

    public List<Partner> getListOfBranches() {
        return listOfBranches;
    }

    public void setListOfBranches(List<Partner> listOfBranches) {
        this.listOfBranches = listOfBranches;
    }

    public List<PartnerAccount> getListOfEmployees() {
        return listOfEmployees;
    }

    public void setListOfEmployees(List<PartnerAccount> listOfEmployees) {
        this.listOfEmployees = listOfEmployees;
    }

    public String getBusinessAddress1() {
        return businessAddress1;
    }

    public void setBusinessAddress1(String businessAddress1) {
        this.businessAddress1 = businessAddress1;
    }

    public String getBusinessAddress2() {
        return businessAddress2;
    }

    public void setBusinessAddress2(String businessAddress2) {
        this.businessAddress2 = businessAddress2;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getProvince() {
        return province;
    }

    public void setProvince(String province) {
        this.province = province;
    } 

    public String getBusinessEmail() {
        return businessEmail;
    }

    public void setBusinessEmail(String businessEmail) {
        this.businessEmail = businessEmail;
    }

    public int getSector() {
        return sector;
    }

    public void setSector(int sector) {
        this.sector = sector;
    }

    public List<Outlet> getListOfOutlets() {
        return listOfOutlets;
    }

    public void setListOfOutlets(List<Outlet> listOfOutlets) {
        this.listOfOutlets = listOfOutlets;
    }

    public boolean isBranch() {
        return branch;
    }

    public void setBranch(boolean branch) {
        this.branch = branch;
    }

    public List<TermsAndConditions> getListOfTC() {
        return listOfTC;
    }

    public void setListOfTC(List<TermsAndConditions> listOfTC) {
        this.listOfTC = listOfTC;
    }

    public String getBillingAddress1() {
        return billingAddress1;
    }

    public void setBillingAddress1(String billingAddress1) {
        this.billingAddress1 = billingAddress1;
    }

    public String getBillingAddress2() {
        return billingAddress2;
    }

    public void setBillingAddress2(String billingAddress2) {
        this.billingAddress2 = billingAddress2;
    }

    public String getBillingPostalCode() {
        return billingPostalCode;
    }

    public void setBillingPostalCode(String billingPostalCode) {
        this.billingPostalCode = billingPostalCode;
    }

    public String getBusinessPostalCode() {
        return businessPostalCode;
    }

    public void setBusinessPostalCode(String businessPostalCode) {
        this.businessPostalCode = businessPostalCode;
    }

    public String getCountryCode() {
        return countryCode;
    }

    public void setCountryCode(String countryCode) {
        this.countryCode = countryCode;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public int getReservationMinimumLeadTime() {
        return reservationMinimumLeadTime;
    }

    public void setReservationMinimumLeadTime(int reservationMinimumLeadTime) {
        this.reservationMinimumLeadTime = reservationMinimumLeadTime;
    }
    
    public int getReservationMaximumLeadTime() {
        return reservationMaximumLeadTime;
    }

    public void setReservationMaximumLeadTime(int reservationMaximumLeadTime) {
        this.reservationMaximumLeadTime = reservationMaximumLeadTime;
    }

    public int getReservableMinimumLength() {
        return reservableMinimumLength;
    }

    public void setReservableMinimumLength(int reservableMinimumLength) {
        this.reservableMinimumLength = reservableMinimumLength;
    }

    public int getReservableMaximumLength() {
        return reservableMaximumLength;
    }

    public void setReservableMaximumLength(int reservableMaximumLength) {
        this.reservableMaximumLength = reservableMaximumLength;
    }

    public int getReservationNoShowFee() {
        return reservationNoShowFee;
    }

    public void setReservationNoShowFee(int reservationNoShowFee) {
        this.reservationNoShowFee = reservationNoShowFee;
    }

    public int getReservationCancelFee() {
        return reservationCancelFee;
    }

    public void setReservationCancelFee(int reservationCancelFee) {
        this.reservationCancelFee = reservationCancelFee;
    }

    public List<Files> getListOfInvoices() {
        return listOfInvoices;
    }

    public void setListOfInvoices(List<Files> listOfInvoices) {
        this.listOfInvoices = listOfInvoices;
    }
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Partner)) {
            return false;
        }
        Partner other = (Partner) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entity.Partner[ id=" + id + " ]";
    }
    
}
